#include "BaseApp.h"

#include "cs_login.pb.h"

CBaseApp::CBaseApp()
{
}


CBaseApp::~CBaseApp()
{
    CmdRouteMap::iterator mapItCmdRoute = m_mapCmdRoute.begin();
    for (; mapItCmdRoute != m_mapCmdRoute.end(); ++mapItCmdRoute)
    {
        if (mapItCmdRoute->second != NULL)
        {
            delete mapItCmdRoute->second;
            mapItCmdRoute->second = NULL;
        }
    }
    m_mapCmdRoute.clear();
}

bool CBaseApp::Init()
{
    return true;
}

int CBaseApp::HandleMessage(const comm::Head &pbHead, const google::protobuf::Message &pbMessage)
{
    return 0;
}

int CBaseApp::RmgCmd(int iCmd, google::protobuf::Message* pMessage)
{
    if (iCmd < 0 || pMessage == NULL)
    {
        return -1;
    }

    if (m_mapCmdRoute.find(iCmd) != m_mapCmdRoute.end())
    {
        return -1;
    }

    if (m_mapCmdRoute.insert(pair<int, google::protobuf::Message*>(iCmd, pMessage)).second == false)
    {
        return -1;
    }
    return 0;
}
